// pages/realnamedtl/realnamedtl.js

const app = getApp()
const pathUrl = app.globalData.pathUrl;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    proAry: ['实名认证', '发起公证', '活体检测', '签署完成'],
    agree: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    wx.hideLoading();
    var telphone = wx.getStorageSync('telphone')
    that.setData({
      telphone: telphone
    })
    this.getGuset();
  },
  ocrNameInput: function(e) {
    this.setData({
      ocrName: e.detail.value
    })
  },
  //ocr身份证号
  idCardInput: function(e) {
    this.setData({
      idCard: e.detail.value
    })
  },
  agree: function(e) {
    console.log(e.detail.value)
    if (e.detail.value == '') {
      this.setData({
        agree: false
      });
    } else {
      this.setData({
        agree: true
      });
    }
  },
  getGuset: function(e) {
    var that = this;
    var telphone = wx.getStorageSync('telphone')

    wx.request({
      url: pathUrl + '/gzgl/fxyGzgl02/list',
      method: 'GET',
      data: {
        query12: that.data.telphone,
      },
      success: function(res) {
        console.log(res.data.result.records);
        var list = res.data.result.records;
        that.setData({
          list: list,
          orcName: list[0].query13,
          idCard: list[0].query15
        })
        // if (res.data.success) { // 登陆成功
        //   wx.setStorageSync('loginInfo', JSON.stringify(res.data.result));
        //   wx.navigateTo({
        //     url: "/pages/index/index"
        //   })
        // } else { // 登陆失败
        //   wx.showToast({
        //     title: res.data.message,
        //     icon: 'fail',
        //     duration: 1000
        //   });
        // }
      },
      fail: function(res) {}
    });
  },
  // 再试一次 
  goTry: function() {
    wx.navigateBack({
      delta: 1,
    });
  },
  // 提交信息
  goSub: function() {
    if (!this.data.agree) {
      wx.showModal({
        title: '提示',
        content: '请再次同意并勾选协议',
        showCancel: false
      })
      return false;
    }
    // wx.showToast({
    //   title: '提交信息',
    // })
    var that = this;
    var fileId = wx.getStorageSync('fileId')
    var fileId1 = wx.getStorageSync('fileId1')
    var userId = wx.getStorageSync('userId')
    var idCard = that.data.idCard;
    var orcName = that.data.orcName;
    var telphone = that.data.telphone;

    var data = {
      userId: userId,
      name: orcName,
      idCode: idCard,
      humanFaceFileId: fileId,
      nationalEmblemFileId: fileId1,
    }
    console.log(data)
    wx.request({
      url: pathUrl + '/fxy/1/doRealnameByOCR2Element',
      method: 'POST',
      data: data,
      success: function(res) {
        console.log(res)
        wx.request({
          url: pathUrl + '/gzgl/fxyGzgl02/edit22',
          data: {
            para: telphone
          },
          method: 'PUT',
          success: function(e) {
            console.log(e)
            var orderNo = wx.getStorageSync('orderNo')
            console.log(orderNo)
            wx.request({
              url: pathUrl + '/gzgl/fxyGzgl01/list',
              data: {
                query07: orderNo,
              },
              method: 'GET',
              success: function(res) {
                console.log(res)
                console.log(res.data.result.records)

                var list01 = res.data.result.records;
                var data01 = {
                  createBy: list01[0].createBy,
                  id: list01[0].id,
                  query01: list01[0].query01,
                  query02: list01[0].query02,
                  query03: list01[0].query03,
                  query04: list01[0].query04,
                  query05: list01[0].query05,
                  query06: list01[0].query06,
                  query07: list01[0].query07,
                  query08: list01[0].query08,
                  query09: list01[0].query09,
                  query10: list01[0].query10,
                  query11: list01[0].query11,
                  query12: list01[0].query12,
                  query13: list01[0].query13,
                  query14: list01[0].query14,
                  query15: list01[0].query15,
                  query16: list01[0].query16,
                  query17: list01[0].query17,
                  query18: list01[0].query18,
                  query19: list01[0].query19,
                  query20: list01[0].query20,
                  query21: list01[0].query21,
                  query22: list01[0].query22,
                  query23: list01[0].query23,
                  query24: list01[0].query24,
                  query25: list01[0].query25,
                  query26: list01[0].query26,
                  query27: list01[0].query27,
                  query28: list01[0].query28,
                  query29: list01[0].query29,
                  query30: list01[0].query30,
                  query31: list01[0].query31,
                  query32: list01[0].query32,
                  query33: list01[0].query33,
                  query34: list01[0].query34,
                  query35: list01[0].query35,
                  query36: list01[0].query36,
                  query37: list01[0].query37,
                  query38: list01[0].query38,
                  query39: 'Y',
                  sysOrgCode: list01[0].sysOrgCode,
                  updateBy: list01[0].updateBy,
                  updateTime: list01[0].updateTime
                }
                wx.request({
                  url: pathUrl + '/gzgl/fxyGzgl01/edit',
                  method: 'PUT',
                  data: data01,
                  success: function(res) {
                    console.log(res)
                    wx.showModal({
                      title: '提示',
                      content: res.data.message,
                      showCancel: false,
                      success(res) {
                        console.log(res)
                        wx.setStorageSync('sfsm', '已实名');
                        wx.reLaunch({
                          url: '/pages/addr/addr',
                        })
                      },
                    })
                  },
                })
              }
            })
          }
        })
      },
      fail: function(res) {
        wx.showModal({
          title: '提示',
          content: '实名失败',
          showCancel: false,
          success(res) {
            console.log(res)
            // wx.setStorageSync('sfsm', '已实名');
            wx.reLaunch({
              url: '/pages/inedx/inedx',
            })
          },
        })
      },
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})